<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- import common templates -->
<xsl:import href="../xml/templates/common.xsl"/>  
<!-- import main_app templates -->
<xsl:import href="../xml/templates/nav_app.xsl"/>
<!-- xsl output -->
<xsl:output method='html' encoding='UTF-8' doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" indent='yes'/>
	
	<!-- template to generate main content -->
	<xsl:template name="ProfileContent">
		<!-- load extra tabindex params 
		<xsl:call-template name="ExtraDataLoader">
			<xsl:with-param name="src" select="extradata/tabindex"/>
		</xsl:call-template> -->
		<!-- main tab page -->
		<div id="tab_wrapper">
   			<h1>User Settings</h1>
			<form id="personal_form" method="post" action="../cgi-bin/profilemanage.pl">
				<fieldset id="personal"><legend>Change Personal details</legend>
					<ul>
						<li><label for="first_name">First Name </label><input id="first_name" name="first_name"  type="text">
							<xsl:attribute name="value"><xsl:value-of select="input/first_name"/></xsl:attribute></input>
							<!-- error -->
							<xsl:if test="input/err_fname = 'empty'">
								<span class="error_box" id="first_name_err">Field was empty</span>
							</xsl:if>
						</li>
						<li><label for="last_name">Last Name </label><input id="last_name" name="last_name" type="text" >
							<xsl:attribute name="value"><xsl:value-of select="input/last_name"/></xsl:attribute></input>
							<!-- error -->
							<xsl:if test="input/err_lname = 'empty'">
								<span class="error_box" id="first_name_err">Field was empty</span>
							</xsl:if>
						</li>
						<li><label for="email">Email </label><input id="email" name="email" type="text" >
							<xsl:attribute name="value"><xsl:value-of select="input/email"/></xsl:attribute></input>
							<!-- required -->
							<xsl:if test="input/err_email = 'empty'">
								<span class="error_box" id="email_err">Field was empty</span>
							</xsl:if>
							<!-- invalid format -->
							<xsl:if test="input/err_email = 'format'">
								<span class="error_box" id="email_err">Not valid email format</span>
							</xsl:if>
							<!-- already used -->
							<xsl:if test="input/err_email = 'present'">
								<span class="error_box" id="email_err">Email already used</span>
							</xsl:if>
						</li>
						<li>
							<label>Gender</label>
							<ul>
								<li>
									<input type="radio" name="gender" id="male_gender" value="male" >
										<xsl:if test="input/gender/text() = 'male'">
											<xsl:attribute name="checked">true</xsl:attribute>
										</xsl:if>
									</input>
									<label for="male-gender" id="male_label" class="inner_label">male</label>
								</li>
								<li>
									<input type="radio" name="gender" value="female" id="female_gender">
										<xsl:if test="input/gender/text() = 'female'">
											<xsl:attribute name="checked">true</xsl:attribute>
										</xsl:if>
									</input>
									<label for="female-gender" id="female_label" class="inner_label" >female</label>
								</li>
							</ul>
						</li>
					</ul>
					<input type="submit" id="submit_personal" value="Change My Info!" onclick="if(!FormChecker.check()) return false;"/>
					<input type="reset" id="reset_personal" value="Reset"/>
					<input type="hidden" name="id"><xsl:attribute name="value"><xsl:value-of select="input/id"/></xsl:attribute></input>
					<input type="hidden" name="filedata"><xsl:attribute name="value"><xsl:value-of select="input/filedata"/></xsl:attribute></input>
					<input type="hidden" name="userdata" value="1"/>
					<!-- success -->
					<xsl:if test="input/usrchanged">
						<p id="subscribed" class="subscribed"><xsl:value-of select="input/usrchanged"/></p>
					</xsl:if>					
				</fieldset>
			</form>
			<form id="psw_form" method="post" action="../cgi-bin/profilemanage.pl">
				<fieldset id="pass_change"><legend>Change Password</legend>
					<ul>
						<li><label for="old_password">Old Password </label><input id="old_password" name="old_password" type="password" />
							<!-- password error -->
							<xsl:if test="input/err_opsw = 'empty'">
								<span class="error_box" id="password_err">Required field</span>
							</xsl:if>
							<xsl:if test="input/err_opsw = 'wrong'">
								<span class="error_box" id="password_err">Wrong Password</span>
							</xsl:if>
						</li>
						<li><label for="new_password">New Password </label><input id="new_password" name="new_password" type="password" />
							<!-- password error -->
							<xsl:if test="input/err_npsw = 'empty'">
								<span class="error_box" id="password_err">Required field</span>
							</xsl:if>
							<xsl:if test="input/err_npsw = 'length'">
								<span class="error_box" id="password_err">6 chars at least</span>
							</xsl:if>
						</li>
						<li><label for="confirm_new_password">Confirm New Password </label><input id="confirm_new_password" name="confirm_new_password" type="password" />
							<!-- confirm_password error -->
							<xsl:if test="input/err_cpsw = 'mismatch'">
								<span class="error_box" id="confirm_password_err">Check for typo</span>
							</xsl:if>
						</li>
					</ul>
				<input type="submit" id="submit_psw" value="Change Password!" onclick="if(!FormChecker.check()) return false;"/>
				<input type="hidden" name="id"><xsl:attribute name="value"><xsl:value-of select="input/id"/></xsl:attribute></input>
				<input type="hidden" name="pswdata" value="1"/>
				<!-- success -->
				<xsl:if test="input/pswchanged">
					<p id="subscribed" class="subscribed"><xsl:value-of select="input/pswchanged"/></p>
				</xsl:if>
				</fieldset>  
			</form>
		</div>
	</xsl:template>
	
	<!-- CREATE PAGE -->
	
	<!-- create page structure -->
	<xsl:template match="root">
		<html>
			<!-- head -->
			<head>
				<!-- load common code -->
				<xsl:call-template name="Loader">
					<xsl:with-param name="src" select="$src_head"/>
				</xsl:call-template>
				<!-- load extra head params -->
				<xsl:call-template name="ExtraDataLoader">
					<xsl:with-param name="src" select="extradata/head"/>
				</xsl:call-template>
				<!-- load ie fix -->
				<xsl:call-template name="IELoader">
					<xsl:with-param name="src" select="$src_head_ie/root/common"/>
				</xsl:call-template>
				<xsl:call-template name="IELoader">
					<xsl:with-param name="src" select="extradata/IEFix"/>
				</xsl:call-template>
				<!-- pagetitle -->
				<title><xsl:value-of select="pagetitle"/></title>
			</head>
			<body>
				<!-- body onload attribute -->
				<xsl:if test="extradata/body/onload/text() != ''">
					<xsl:attribute name="onLoad"><xsl:value-of select="extradata/body/onload"/></xsl:attribute>
				</xsl:if>
				<!-- header -->			
				<xsl:call-template name="Loader">
					<xsl:with-param name="src" select="$src_header"/>
				</xsl:call-template>
				<!-- profile -->
				<xsl:call-template name="ProfileLoader">
					<xsl:with-param name="sid" select="input/id"/>
					<xsl:with-param name="page" select="page"/>
				</xsl:call-template>				
				<!-- navbar -->
				<div id="main_app_navigation">
					<xsl:call-template name="NavAppLoader">
						<xsl:with-param name="src" select="$src_navbar"/>
					</xsl:call-template>
				</div>
				<!-- content -->
				<xsl:call-template name="ProfileContent">
					<!--<xsl:with-param name="src" select="$src_footer"/>-->
				</xsl:call-template>				
				<!-- footer -->
				<xsl:call-template name="Loader">
					<xsl:with-param name="src" select="$src_footer"/>
				</xsl:call-template>				
			</body>
		</html>
	</xsl:template>
	
</xsl:stylesheet>	
